package com.yunduansing.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunduansing.core.commons.DbCommon;
import com.yunduansing.core.commons.DbCommon.Grid;
import com.yunduansing.core.dao.TemplateTypeDao;
import com.yunduansing.core.model.TemplateTypeModel;
import com.yunduansing.core.service.TemplateTypeService;
import com.yunduansing.core.utils.ResultUtil;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.StringUtil;

@Service
public class TemplateTypeServiceImpl implements TemplateTypeService {
	@Autowired
	private TemplateTypeDao dao;

	/**
	 * 分页查询
	 */
	public Object pagination(Grid grid,String key) {
		DbCommon.Pager pager=new DbCommon.Pager();
		pager.setIndex(grid.getIndex());
		grid.setIndex((grid.getIndex()-1)*grid.getSize());
		pager.setData(dao.pagination(grid,key));
		pager.setRows(dao.pageCount(key));
		return pager;
	}

	public ResultUtil save(TemplateTypeModel model) {
		if(model.getId()>0){
			return ResultUtil.init(dao.update(model));
		}
		return ResultUtil.init(dao.add(model));
	}

	public TemplateTypeModel getById(int id) {
		if(id==0)
			return null;
		return dao.getById(id);
	}

	public ResultUtil deleteByIds(List<Integer> ids) {
		if(ids.isEmpty())
			return ResultUtil.init(false,"请选择要删除的数据");
		return ResultUtil.init(dao.delete(ids));
	}

	public List<TemplateTypeModel> getAll() {
		return dao.getAll();
	}

}
